<script>
// 任务一、答题页面
export default {
  name: "TxFourComm",
  data(){
    return {
      show_aq:false,
      question:'',
      show_btn1:true,
      show_card1:false,
      show_card2:false,
      show_card3:false,
      is_loaded:false,
      start_time:'',
      end_time:'',
      first:'',
      second:'',
      thrid:''
    }
  },

  methods:{
    //图片加载成功后，显示按钮
    img_load_success(){
        this.is_loaded = true;
    },

    //显示答题组件
    show_comm(question){
      this.question = question;
      this.show_aq = true;
      this.show_btn1 = true;
      this.hide_btn();
    },


    // +号按钮300毫秒后消失
    hide_btn(){
      const _this = this;
      this.$nextTick(function(){
        setTimeout(function(){
          _this.show_btn1 = false;
          _this.show_card1 = true;
          _this.start_time = new Date().getTime();
        },300)
      })
    },

    //用户选择答案，并统计用户答题时长
    choose_answer(ans){
      //统计结束时间
      this.end_time = new Date().getTime();
      var spend_time = Math.abs(this.end_time - this.start_time);
      //统计答案是否正确
      var is_right = '是';

      if(this.question.rightAnswer != ans){
        is_right = '否';
      }


      //显示空屏
      this.show_card1 = false;
      this.show_card2 = true;

      //300毫秒后，空屏隐藏，进入下一题
      const _this = this;
      this.$nextTick(function(){
        setTimeout(function(){
          _this.clsar_data();
          _this.$emit('ans_finish',ans,spend_time,is_right); //空屏显示300ms之后，回调父函数，传给父元素答案，并告知父元素进入下一题
        },300)
      })
    },

    //答题完成---清空答题组件
    clsar_data(){
      this.show_aq = false;
      this.question='';
      this.show_btn1=true;
      this.show_card1=false;
      this.show_card2=false;
    }


  }
}
</script>

<template>
  <div v-if="show_aq" style="width:80%;">
    <div v-if="show_btn1" class="card1_plus">
      <div  ref="btn1" class="card1_btn1" >+</div>
    </div>

    <div v-if="show_card1" class="card1">
      <div class="que_sty">
        <el-image @load="img_load_success" :src="'http://8.152.4.101:9999/'+question.imgQuestion" style="width: 40%"></el-image>
<!--         <el-image @load="img_load_success" :src="'http://localhost:9999/'+question.imgQuestion" style="width: 40%"></el-image>-->
      </div>
      <div v-if="is_loaded" class="div_btn1">
        <div class="aqc_div2">
          <el-button  class="btn2" type="primary" @click="choose_answer('好')">&nbsp;&nbsp;好&nbsp;&nbsp;</el-button>
        </div>
        <div class="aqc_div2">
          <el-button  class="btn2" type="primary" @click="choose_answer('无')">&nbsp;&nbsp;无&nbsp;&nbsp;</el-button>
        </div>
        <div class="aqc_div3">
         <el-button   class="btn2" type="primary" @click="choose_answer('不好')">不好</el-button>
        </div>
      </div>
    </div>


    <!--          空屏显示300毫秒-->
    <div v-if="show_card2" class="card1"></div>


  </div>
</template>

<style scoped>
.card1_btn1{
  width: 200px;
  height: 200px;
  line-height: 170px;
  font-size: 250px;
  color:red;
}
.card1_plus{
  text-align: center;
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 5%;
}
.card1{
  text-align: center;
  width: 100%;
}
.que_sty{
  color: #050505;
  font-size: 160px;
  font-weight: 700;
  //display: flex;
  //justify-content: space-around;
}
.sub_title{
  font-size: 50px;
}

.div_btn1{
  display: flex;
  justify-content: space-around;
  margin-top: 20px;
}
.btn2{
  width: 100%;
  height: 90px;
  font-size: 60px;
  display: inline-block;
}
.aqc_div3{
  //margin-left: 20%;
}
</style>